<template>
	<view class="orderList">
		<view class="top-tabs" style="background: #FFFFFF;">
			<u-subsection :list="list" inactiveColor="#303133" activeColor="#3c9cff" keyName="name" :current="curNow"
				mode="subsection" @change="sectionChange" ></u-subsection>
		</view>
		<!-- 卡片板块 -->
		<view class="card-box">
			<!-- 渲染的卡片列表 -->
			<view class="card-body" v-for="(item, index) in orderList" :key="index">
				<view class="card-title-body">
					<!-- 头部 -->
					<view class="public-praise">
						优
					</view>
					<view style="font-size: 28rpx; font-weight: 500;">
						{{item.storeName}}
					</view>
					<view style="font-size: 28rpx;margin-left: auto; color: #D2B48C;">
						{{item.subscribeState == '0'?'待服务':(item.subscribeState == '1'?'已完成':(item.subscribeState == '2'?'已退款':'已过期'))}}
					</view>
				</view>
				<!-- 图片数据部 -->
				<!-- 顶部项目图片与介绍 -->
				<view class="title-project-body-title">
					<image :src="item.skuDefaultImg" mode="scaleToFill" style="width: 120rpx; height: 120rpx; border-radius: 10rpx;"></image>
					<view class="order-info-text" style="margin-left: 20rpx; margin-right: 50rpx;">
						<view style="font-size: 28rpx; font-weight: 500;">
							{{item.skuName}}
						</view>
						<view style="font-size: 24rpx; margin-top: 10rpx; color: gray;">
							{{item.skuDesc == null?'无介绍描述':item.skuDesc}}
						</view>
					</view>
					<view class="card-money-box">
						<!-- <view v-if="productMap.linePrice != productMap.price"
							style="font-size: 24rpx; font-weight: bold; text-decoration: line-through; color: gray;">
							￥{{productMap.linePrice}}
						</view> -->
						<view style="font-size: 28rpx; font-weight: 500;">
							￥{{item.projectMoney}}
						</view>
						<view style="font-size: 24rpx; margin-top: 10rpx; color: #999999;">
							x {{item.amount}}
						</view>
					</view>
				</view>
				<view class="total-amount-box">
					<view class="" style="margin-right: 10rpx;">
						共{{item.amount}}件
					</view>
					<view class="">
						实付总额：<span style="font-size: 32rpx; font-weight: 500; color: #8B0000;">￥{{item.projectMoney}}</span>
					</view>
				</view>
			
				<view class="show-order-info">
					<view class="click-show-buttom" @click="ClickShowOrderInfo(item)">
						查看预约
					</view>
				</view>
				
				<!-- 订单相关信息 -->
				<view class="order-style-info-box">
					<view class="info-title-box">
						<!-- 头部 -->
						<view class="public-praise" style="width: 60rpx; color: #D2B48C !important;">
							{{item.subscribeType == '1'?'到店':'上门'}}
						</view>
						<view style="font-size: 26rpx; font-weight: 500; color: #000000;">
							{{item.storeName}}
						</view>
						<view style="font-size: 26rpx;margin-left: auto; margin-right: 0rpx; color: #D2B48C;">
							{{item.subscribeType == '1'?'待到店服务':'待上门服务'}}
						</view>
					</view>
					
					<view class="text-info-show" style="margin-top: 20rpx;">
						服务店铺：{{item.storeName}}
					</view>
					<view class="text-info-show" style="margin-top: 10rpx; margin-bottom: 10rpx;">
						服务地址：{{item.storeAddress}}
					</view>
					<view class="text-info-show">
						服务时间：{{item.subscribeTime == null?'待服务':item.subscribeTime}}
					</view>
					
					<view class="buttom-row-click-box">
						<view class="buttom-dibu" @click="showCode(item)" v-if="item.paymentTime != null && item.subscribeState == '0'">
							查看劵码
						</view>
						<view class="buttom-dibu" style="margin-left: 15rpx; margin-right: 15rpx;">
							去导航
						</view>
						<view class="buttom-dibu" style="color: #D2B48C;">
							联系TA
						</view>
					</view>
					
				</view>			
			</view>
		</view>
		<!-- 弹出劵码：二维码 -->
		<view class="show-code-box" v-if="show" @click="hideCode">	
			<view class="image-title">
				<image src="../../../static/image/poster.png" mode="scaleToFill" style="width: 120rpx; height: 120rpx;"></image>
			</view>
			<view class="code-image" >
				<uqrcode ref="uQRCode" mode="canvas" size="200" :text="textCode" />
				<view style="margin-top: 20rpx; color: #000000; font-size: 28rpx; font-weight: 500;">
					请在服务完成后让手艺人扫码
				</view>
				<button class="save-image-code" @click.stop="saveImage">保存图片</button>
			</view>
			<!-- <u-icon name="close-circle" color="#FFFFFF" size="56" style="margin-top: 20rpx;"></u-icon> -->
		</view>
	</view>
</template>

<script>
	import ayQrcode from "@/config/qrcode.js"
	import {
		mapState
	} from 'vuex';
	export default {
		data() {
			return {
				// 劵码
				textCode: '',
				// 弹窗状态
				show: false,
				// 测试数据
				orderList: [],
				list: [{
						name: '待服务',
						value: 0
					}, {
						name: '已完成',
						value: 1
					}, {
						name: '已退款',
						value: 2
					},
					{
						name: '已过期',
						value: 3
					}
				],
				curNow: 0
			}
		},
		onLoad() {
			this.getMyOrderList()
		},
		// onShow() {

		// },
		computed: {
			...mapState(['hasLogin', 'userInfo'])
		},
		methods: {
			// 查看订单详情
			ClickShowOrderInfo(item){
				let status = item.subscribeState == '0'?'1':(item.subscribeState == '1'?'3':(item.subscribeState == '2'?'4':'5'))
				uni.navigateTo({
					url: 'index?status=' + status,
					success(res) {
						res.eventChannel.emit('item', item)
					}
				})
			},
			// 关闭查看二维码
			hideCode(){
				this.show = false
				this.getMyOrderList()
			},
			// 获取预约记录数据
			getMyOrderList() {
				this.$api.request.getMyDataList({
					wxId: uni.getStorageSync('userInfo').id,
					status: this.curNow
				}, res => {
					if(res.code == 200){
						console.log(res);
						this.orderList = res.data
					}					
				})
			},
			// 点击 tabs 导航栏
			sectionChange(index) {
				const that = this
				console.log(index);
				that.curNow = index;
				that.getMyOrderList()
			},
			// 查看劵码
			showCode(item){
				this.textCode = item.checkoutCode
				this.show = true
			},
			// 保存二维码
			// 保存图片
			saveImage(){
				console.log("点击了保存");
				const that = this
				that.$refs.uQRCode.save()
			},

		}
	}
</script>

<style>
	.orderList {
		width: 100vw;
		height: 100vh;
		overflow-y: scroll;
		background: #F6F6F6;
	}

	.top-tabs {
		width: 100vw;
		height: 70rpx;
		position: absolute;
		top: 0;
		left: 0;
	}

	.card-box {
		width: 100vw;
		height: calc(100% - 120rpx);
		overflow-y: scroll;
		margin-top: 100rpx;
		/* border: 1rpx solid red; */
	}

	.card-body {
		width: auto;
		background: #FFFFFF;
		margin: 0 20rpx;
		margin-bottom: 30rpx;
		border-radius: 15rpx;
		display: flex;
		flex-direction: column;
	}

	.card-title-body {
		display: flex;
		flex-direction: row;
		align-items: center;
		padding: 20rpx 20rpx;
	}

	.public-praise {
		width: 30rpx;
		height: 30rpx;
		border: 1rpx solid #D2B48C;
		border-radius: 5rpx;
		font-size: 22rpx;
		display: flex;
		justify-content: center;
		color: #D2B48C;
		margin-right: 10rpx;
	}

	.title-project-body-title {
		display: flex;
		flex-direction: row;
		margin: 20rpx 20rpx;
	}

	.order-info-text {
		width: calc(100vw - 375rpx);
		display: flex;
		flex-direction: column;
	}

	.card-money-box {
		display: flex;
		flex-direction: column;
		align-items: flex-end;
		margin-left: auto;
		margin-right: 0;
	}
	
	.total-amount-box{
		width: auto;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: flex-end;
		font-size: 28rpx;
		font-weight: 500;
		margin-right: 20rpx;
	}
	
	.buttom-box-row{
		width: auto;
		display: flex;
		align-items: center;
		justify-content: flex-end;
	}
	
	.show-order-info{
		width: auto;
		display: flex;
		flex-direction: row;
		justify-content: flex-end;
	}
	.click-show-buttom{
		width: auto;
		height: 40rpx;
		font-size: 28rpx;
		font-weight: 500;
		padding: 10rpx 40rpx;
		line-height: 40rpx;
		background: #D2B48C;
		color: #FFFFFF;
		border-radius: 30rpx;
		margin: 20rpx 20rpx;
	}
	
	.order-style-info-box{
		width: auto;
		height: 250rpx;
		background: #F5F5F8;
		margin: 30rpx;
		border-radius: 10rpx;
		display: flex;
		flex-direction: column;
		padding: 15rpx 15rpx;
	}
	
	.info-title-box{
		width: auto;
		display: flex;
		flex-direction: row;
	}
	
	.text-info-show{
		width: auto;
		font-size: 24rpx;
		color: #888888;
		overflow: hidden;
		text-overflow:ellipsis;
		white-space: nowrap;
	}
	
	.buttom-row-click-box{
		width: auto;
		display: flex;
		flex-direction: row;
		justify-content: flex-end;
		align-items: center;
		font-size: 24rpx;
		font-weight: 500;
		margin-top: 25rpx;
	}
	
	.buttom-dibu{
		width: auto;
		/* height: 30rpx; */
		line-height: 30rpx;
		padding: 10rpx 30rpx;
		background: #FFFFFF;
		border: 1rpx solid #F5F5F5;
		border-radius: 25rpx;
	}
	
	.code-image{
		width: 420rpx;
		height: 420rpx;
		background: #FFFFFF;
		display: flex;
		justify-content: center;
		align-items: center;
		z-index: 9999 !important;
	}
	
	.show-code-box{
		width: 100vw;
		height: 100vh;
		position: absolute;
		top: 0;
		left: 0;
		right: 0;
		background: rgb(0,0,0,0.6);
		z-index: 99;
		display: flex;
		justify-content: center;
		flex-direction: column;
		align-items: center;
	}
	
	.code-image{
		width: 560rpx;
		height: 800rpx;
		background: #FFFFFF;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		border-radius: 30rpx;
		border: 3rpx solid #696969;		
		z-index: 9999 !important;
	}
	
	.image-title{
		width: 120rpx;
		height: 120rpx;
		border-radius: 120rpx;
		border: 6rpx solid #696969;
		position: relative;
		bottom: -60rpx;
		background: #fa3534;
		z-index: 99999;
	}
	
	.save-image-code{
		width: 84%;
		height: 80rpx;
		font-size: 28rpx;
		background: #fa3534;
		color: #FFFFFF;
		margin-top: 40rpx;
		border-radius: 80rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}
</style>
